package com.xxl.spinrgbootwebproject.redis;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;

import redis.clients.jedis.JedisPoolConfig;

/**
 * 
 * 【Redis配置服务】
 * @author gbifp
 * @date 2018年3月7日 下午4:27:35 
 * @version V1.0
 */
    @Configuration  
    @EnableAutoConfiguration  
    public class RedisConfig {  
      
        private static final Logger log = LoggerFactory.getLogger(RedisConfig.class);
          
        @Bean  
        @ConfigurationProperties(prefix="spring.redis")  
        public JedisPoolConfig getRedisConfig(){  
            JedisPoolConfig config = new JedisPoolConfig();  
            return config;  
        }  
          
        @Bean  
        @ConfigurationProperties(prefix="spring.redis")  
        public JedisConnectionFactory getConnectionFactory(){  
            JedisConnectionFactory factory = new JedisConnectionFactory();  
            JedisPoolConfig config = getRedisConfig();  
            factory.setPoolConfig(config);  
            log.info("JedisConnectionFactory bean init success.");  
            return factory;  
        }  
          
          
        @Bean  
        public RedisTemplate<?, ?> getRedisTemplate(){  
            RedisTemplate<?,?> template = new StringRedisTemplate(getConnectionFactory());
            return template;  
        }  
    }
    

